home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / What's New? / • What was new 03⁄99 / Development Kits / USBDDK_1.2d3 / Examples / CompositeClassDriver / CompositeDriverDescription.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-18  |  6.4 KB  |  219 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CompositeDriverDescription.c
  3.  
  4.     Contains:    Composite Class Driver Definition Header
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17.  
  18. #include "CompositeClassDriver.h"
  19. #include "CompositeClassVersion.h"
  20.  
  21. usbCompositePBStruct newInterfacesPB;
  22.  
  23.  
  24. OSStatus CompositeDriverInitInterface(
  25.             UInt32                         interfaceNum, 
  26.             USBInterfaceDescriptor        *interfaceDesc, 
  27.             USBDeviceDescriptor            *deviceDesc, 
  28.             USBDeviceRef                 device);
  29.  
  30. //------------------------------------------------------
  31. //
  32. //    This is the driver description structure that the expert looks for first.
  33. //  If it's here, the information within is used to match the driver
  34. //  to the device whose descriptor was passed to the expert.
  35. //    Information in this block is also used by the expert when an
  36. //  entry is created in the Name Registry.
  37. //
  38. //------------------------------------------------------
  39. USBDriverDescription    TheUSBDriverDescription = 
  40. {
  41.     // Signature info
  42.     kTheUSBDriverDescriptionSignature,
  43.     kInitialUSBDriverDescriptor,
  44.     
  45.     // Device Info
  46.     0,                                        // vendor = not device specific
  47.     0,                                        // product = not device specific
  48.     0,                                        // version of product = not device specific
  49.     0,                                        // protocol = not device specific
  50.     
  51.     // Interface Info    (* I don't think this would always be required...*)                
  52.     0,                                        // Configuration Value
  53.     0,                                        // Interface Number
  54.     0,                                        // Interface Class
  55.     0,                                         // Interface SubClass
  56.     0,                                        // Interface Protocol
  57.         
  58.     
  59.     // Driver Info
  60.     "\pUSBCompositeDevice",                    // Driver name for Name Registry
  61.     kUSBCompositeClass,                        // Device Class  (from USBDeviceDefines.h)
  62.     kUSBCompositeSubClass,                    // Device Subclass 
  63.     kCMPHexMajorVers, 
  64.     kCMPHexMinorVers, 
  65.     kCMPCurrentRelease, 
  66.     kCMPReleaseStage,                        // version of driver
  67.     
  68.     // Driver Loading Info
  69.     kUSBDoNotMatchInterface                    // Please don't load us as an interface driver.
  70. };
  71.  
  72. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  73. {
  74.     kClassDriverPluginVersion,                // Version of this structure
  75.     CompositeDriverValidateHW,                // Hardware Validation Procedure
  76.     CompositeDriverInitialize,                // Initialization Procedure
  77.     CompositeDriverInitInterface,            // Interface Initialization Procedure
  78.     CompositeDriverFinalize,                    // Finalization Procedure
  79.     CompositeDriverNotifyProc                // Driver Notification Procedure
  80. };
  81.  
  82. // hubDriverInitInterface function
  83. // Called to initialize driver for an individual interface - either by expert or
  84. // internally by driver
  85. OSStatus CompositeDriverInitInterface(
  86.             UInt32                         interfaceNum, 
  87.             USBInterfaceDescriptor        *interfaceDesc, 
  88.             USBDeviceDescriptor            *deviceDesc, 
  89.             USBDeviceRef                 device)
  90. {
  91. #pragma unused (interfaceNum)
  92. #pragma unused (interfaceDesc)
  93. #pragma unused (deviceDesc)
  94. #pragma unused (device)
  95.  
  96.     return (OSStatus)kUSBNoErr;
  97. }
  98.  
  99. OSStatus    CompositeDriverNotifyProc(UInt32     notification, void *pointer, UInt32 refcon)
  100. {
  101. #pragma unused (pointer)
  102. #pragma unused (refcon)
  103.  
  104. OSStatus    myErr;
  105. OSStatus     status = kUSBNoErr;
  106. static    UInt32    interfacenum = 0;
  107.  
  108.     switch (notification)
  109.     {
  110.         case kNotifyDriverBeingRemoved:
  111.             newInterfacesPB.driverRemovalPending = true;
  112.                 
  113.             if (newInterfacesPB.pb.usbRefcon & kCompletionPending)
  114.             {
  115.                 USBExpertStatus(newInterfacesPB.deviceRef, kCompositeDriverName": Waiting for transaction to complete", newInterfacesPB.pb.usbRefcon);
  116.                 status = kUSBDeviceBusy;
  117.             }
  118.             else
  119.             {
  120.                 if (interfacenum < newInterfacesPB.interfaceCount)        
  121.                 {
  122.                     USBExpertRemoveInterfaceDriver(newInterfacesPB.interfaceRefArray[interfacenum]);
  123.                     InitParamBlock(newInterfacesPB.interfaceRefArray[interfacenum], &newInterfacesPB.pb);
  124.                     newInterfacesPB.pb.usbRefcon = 0;             
  125.                     newInterfacesPB.pb.usbCompletion = (USBCompletion)kUSBNoCallBack;
  126.                     myErr = USBDisposeInterfaceRef(&newInterfacesPB.pb);
  127.                     if(immediateError(myErr))
  128.                     {
  129.                         USBExpertFatalError(newInterfacesPB.interfaceRefArray[interfacenum], kUSBInternalErr, kCompositeDriverName" - USBDisposeInterfaceRef - immediate error", myErr);
  130.                     }
  131.                     interfacenum++;
  132.                     status = kUSBDeviceBusy;
  133.                 }
  134.                 else
  135.                 {
  136.                     if (newInterfacesPB.pFullConfigDescriptor)
  137.                     {
  138.                         InitParamBlock(newInterfacesPB.deviceRef, &newInterfacesPB.pb);
  139.                         newInterfacesPB.pb.usbRefcon = 0;             
  140.                         newInterfacesPB.pb.usbBuffer = newInterfacesPB.pFullConfigDescriptor;        
  141.                         newInterfacesPB.pb.usbCompletion = (USBCompletion)kUSBNoCallBack;
  142.                         myErr = USBDeallocMem(&newInterfacesPB.pb);
  143.                         newInterfacesPB.pFullConfigDescriptor = nil;
  144.                         status = kUSBDeviceBusy;
  145.                     }
  146.                     else
  147.                     {
  148.                         status = kUSBNoErr;
  149.                     }
  150.                 }
  151.             }
  152.             break;
  153.             
  154.         default:
  155.             break;
  156.     }
  157.     return status;
  158. }
  159.  
  160. // Hardware Validation
  161. // Called upon load by Expert
  162. OSStatus CompositeDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  163. {
  164. #pragma unused (device)
  165. #pragma unused (desc)
  166.  
  167.     return (OSStatus)kUSBNoErr;
  168. }
  169.  
  170. // Initialization function
  171. // Called upon load by Expert
  172. OSStatus     CompositeDriverInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc,  UInt32 busPowerAvailable)
  173. {
  174.     // don't let a race condition occur; prevent finalizing until we're all done.
  175.     DeviceInitialize(device, pDesc, busPowerAvailable);
  176.     return (OSStatus)kUSBNoErr;
  177. }
  178.  
  179. // Termination function
  180. // Called by Expert when driver is being shut down
  181. OSStatus CompositeDriverFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  182. {
  183. #pragma unused (pDesc)
  184.  
  185.     USBExpertStatus(theDeviceRef, kCompositeDriverName" - Finalize", 0);
  186.     return (OSStatus)kUSBNoErr;
  187. }
  188.  
  189. void DeviceInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDeviceDescriptor, UInt32 busPowerAvailable)
  190. {
  191. static Boolean beenThereDoneThat = false;
  192.  
  193.     if(beenThereDoneThat)
  194.     {
  195.         USBExpertFatalError(device, kUSBInternalErr, kCompositeDriverName" is not reentrant!", 0);
  196.         return;
  197.     }
  198.     beenThereDoneThat = true;
  199.     
  200.     newInterfacesPB.driverRemovalPending = false;
  201.     
  202.     newInterfacesPB.deviceRef = device;    
  203.     newInterfacesPB.deviceDescriptor = *pDeviceDescriptor;    
  204.     
  205.     newInterfacesPB.busPowerAvailable = busPowerAvailable;                            
  206.     newInterfacesPB.delayLevel = 0;                            
  207.     newInterfacesPB.transDepth = 0;                            
  208.     newInterfacesPB.retryCount = kCompositeRetryCount;
  209.     newInterfacesPB.pFullConfigDescriptor = nil;
  210.     
  211.     InitParamBlock(device, &newInterfacesPB.pb);
  212.     newInterfacesPB.pb.usbRefcon = kGetFullConfiguration0;            /* Start out at first state */
  213.     
  214. //    DebugStr("\pIn Composite Driver");
  215.     CompositeDeviceInitiateTransaction(&newInterfacesPB.pb);
  216. }
  217.  
  218.  
  219.